package com.atguigu.gulimall.cart.exception;

import com.atguigu.common.utils.R;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class RuntimeExceptionHandler {

    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public R handler(RuntimeException ex) {
        return R.error(ex.getMessage());
    }


    @ExceptionHandler(CartExceptionHandler.class)
    @ResponseBody
    public R userHandler(CartExceptionHandler cartExceptionHandler) {
        return R.error("购物车没有此商品");
    }
}
